/*
 * =====================================================================================
 *
 *       Filename:  execve.c
 *
 *    Description:  demo of execve
 *
 *        Version:  1.0
 *        Created:  04/13/2012 03:08:34 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Zhiyi Wu (Z.W), zhiyiw@uoregon.edu
 *        Company:  University of Oregon
 *
 * =====================================================================================
 */

#include	"stdio.h"
#include	"unistd.h"
#include	"string.h"
#include	"stdlib.h"


void main(int argc, char **argv,char *envp[]){
	int i=0;
	while (envp[i]!=NULL)
	{printf("%s\n",envp[i]);i++;}
	int byteCount;	//actual number of bytes read from read()
//	char *arg[] = {"", NULL};//arg for execve
	char *arg[] = {"ls","-l", NULL};//arg for execve
//	char *env[] = {"",NULL};//empty arrays for execve
	char *env[] = {"PATH=/week2/", NULL};//empty arrays for execve
	char cmd[1024];  //command you typed
	char feedback[1024]="This is your command result:\n";
	char welcome[1024]="Please input your command(filename with path):";//promopt the input
	write(1, welcome, sizeof(welcome));//write welcome to screen

	byteCount=read(0,cmd,1024);

	cmd[byteCount-1]='\0';
	write(1,feedback,sizeof(feedback));
	syscall(337,1);
	execve(cmd,arg,env);
	return ;
}		/* -----  end of function main  ----- */
